<template>
    <router-view />
</template>

<script setup lang="ts">
    import { onMounted, nextTick } from "vue";
    import useSettingsStore from "@/store/modules/settings";
    import { handleThemeStyle } from "@/utils/theme";
    import { updateGrayMode } from "@/layout/setting";
    import { ConfigKeyEnum } from "@/enums/config";
    import useConfigStore from "@/store/modules/config";
    import { listConfig } from "@/api/system/config";
    import defaultSettings from "@/settings";
    import { useDynamicTitle } from "@/utils/dynamicTitle";
    import { stringToBoolean } from "@/utils/common";
    const settingsStore = useSettingsStore();
    onMounted(() => {
        nextTick(() => {
            handleThemeStyle(settingsStore.theme);
        });
    });
    // 初始化系统参数
    const configStore = useConfigStore();
    listConfig({}).then((res) => {
        if (res["code"] == 200) {
            configStore.initConfig(res["rows"]);
        }
        // 设置系统灰色
        nextTick(() => {
            if (stringToBoolean(configStore.getConfigValue(ConfigKeyEnum.GRAYMODE)) === true) {
                updateGrayMode(true);
            } else {
                updateGrayMode(false);
            }
        });
        /**设置侧边栏是否显示logo
         * 优先级：系统参数配置->setting.ts->布局设置
         */
        const layoutSetting = localStorage.getItem("layout-setting");
        const storageSetting = layoutSetting ? JSON.parse(layoutSetting) : null;
        if (configStore.getConfigValue(ConfigKeyEnum.SIDEBARCONTAINER) != undefined && configStore.getConfigValue(ConfigKeyEnum.SIDEBARCONTAINER)) {
            // 是否显示logo
            settingsStore.changeSetting({ key: "sidebarLogo", value: storageSetting?.sidebarLogo === undefined ? configStore.getConfigParams(ConfigKeyEnum.SIDEBARCONTAINER)["sidebarLogo"] : storageSetting?.sidebarLogo });

            if (configStore.getConfigParams(ConfigKeyEnum.SIDEBARCONTAINER)["sidebarLogoUrl"]) {
                //logo地址
                settingsStore.changeSetting({ key: "sidebarLogoUrl", value: configStore.getConfigParams(ConfigKeyEnum.SIDEBARCONTAINER)["sidebarLogoUrl"] });
            }
            if (configStore.getConfigParams(ConfigKeyEnum.SIDEBARCONTAINER)["sidebarTitle"]) {
                // 设置标题
                defaultSettings.title = configStore.getConfigParams(ConfigKeyEnum.SIDEBARCONTAINER)["sidebarTitle"];
                useDynamicTitle();
            }
        }
    });
</script>
